#include <iostream>
#include <string>

using namespace std;

int main() {

    string s1 = "I am Ray";
    string s2 = "Ray";
    string s3;
    string s4;
    string s5;
    string s6;

    cout << "s1: " << s1 << endl;
    cout << "s1.size(): " << s1.size() << endl;
    cout << "s1.length(): " << s1.length() << endl;
    cout << "s1[0]: " << s1[0] << endl;
    cout << "s1[2]: " << s1[2] << endl;
    cout << endl;

    cout << "s2: " << s2 << endl;
    cout << "s2.size(): " << s2.size() << endl;
    cout << "s2.length(): " << s2.length() << endl;
    cout << endl;

    cout << "please input value for string s3:" << endl;
    getline(cin, s3);
    cout << "s3: " << s3 << endl;
    cout << "s3.size(): " << s3.size() << endl;
    cout << "s3.length(): " << s3.length() << endl;
    cout << endl;

    cout << "please input value for string s4:" << endl;
    getline(cin, s4);
    cout << "s4: " << s4 << endl;
    cout << "s4.size(): " << s4.size() << endl;
    cout << "s4.length(): " << s4.length() << endl;
    cout << endl;

    cout << '/0' << endl;

    // 字符串连接(拼接)
    cout << "s1+s2: " << s1 + s2 << endl;

    s3 += s4;  // s3 = s3 + s4;
    cout << "s3+s4: " << s3 << endl;

    s3 += 'Z'; // s3 = s3 + 'Z';
    cout << "s3+'Z': " << s3 << endl;

    s3 = 'A' + s3; // s3 = 'A' + s3;
    cout << "'A'+s3: " << s3 << endl;

    // 查找字符串
    size_t pos;
    pos = s1.find(s2);
    if (pos != std::string::npos) {
        cout << "s1 contains s2" << endl;
    } else {
        cout << "s1 doesn't contains s2" << endl;
        return 0;
    }

    // 替换字符串
    s1.replace(0, 2, "hu");
    cout << s1 << endl;

    s1.replace(pos, s2.size(), "rui");
    cout << s1 << endl;

    /* 遍历string表示的字符串s1中的每一个字符, 如果遇到大写字母，将其转换成小写字母；
       如果遇到小写字母，将其转换成大写字母 */
    for (int i = 0; i < s1.size(); i++){
        if (s1[i] <= 'Z' && s1[i] >= 'A'){
            s1[i] = s1[i] + 32;
        }else if (s1[i] <= 'z' && s1[i]>= 'a'){
            s1[i] =s1[i] - 32;
        }

    }
    cout << s1 << endl;

    // 删除字符串中指定位置的字符或字符串
    s1.erase(0, 2);
    cout << s1 << endl;

    cout << "please input value for string s5:" << endl;
    getline(cin, s5);
    cout << "s5:" << s5 << endl;

    cout << "please input value for string s6:" << endl;
    getline(cin, s6);
    cout << "s6:" << s6 << endl;

    // 字符串比较大小
    cout << "s5 > s6  :" << (s5 > s6) << endl;
    cout << "s5 >= s6 :" << (s5 >= s6) << endl;
    cout << "s5 == s6 :" << (s5 == s6) << endl;
    cout << "s5 <= s6 :" << (s5 <= s6) << endl;
    cout << "s5 < s6  :" << (s5 < s6) << endl;

    return 0;
}